<style>
.app-main{
  background: #f5f9ff;
}
.sss{
  float: left;
}
</style>
<template>
  <div class="app-container" style="margin: auto; margin-top: 20px; border-radius:5px; width: 80%;  background: #FFFFFF">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-button plain>导入</el-button>
      <el-button @click="handleExport" plain>导出</el-button>
      <el-button plain @click="dayin">打印</el-button><br>

      <br>
      <div>
        <span class="sss" ><el-button  @click="tostatus('')" label="">全部</el-button></span>
        <span class="sss" ><el-button  @click="tostatus('待提货')" label="">待提货</el-button></span>
        <span class="sss" ><el-button  @click="tostatus('已提货')" label="">已提货</el-button></span>
      </div>
      <div style="height: 40px; width: 80%;"></div>
      <br>

      <el-form-item label="始发地" prop="departure" >
        <el-select v-model="queryParams.departure" clearable placeholder="请选择">
          <el-option label="广州市" value="广州市"></el-option>
          <el-option label="深圳" value="深圳"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="目的地" prop="destination" >
        <el-select v-model="queryParams.destination" clearable placeholder="请选择">
          <el-option label="河南" value="河南"></el-option>
          <el-option label="北京" value="北京"></el-option>
          <el-option label="上海" value="上海"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="提货日期" >
        <el-date-picker
          v-model="daterangePickupStartTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="pickupList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="${comment}" align="center" prop="id" />-->
      <el-table-column label="提货单号" align="center" prop="pickupOrderNumber" width="150">
        <template slot-scope="scope">
          <el-link @click="handleUpdate(scope.row)" type="primary">{{scope.row.pickupOrderNumber}}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="运单号" align="center" prop="waybillNumber" width="150" >
        <template slot-scope="scope">
          <el-link @click="handleUpdate1(scope.row)" type="primary">{{scope.row.waybillNumber}}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="订单号" align="center" prop="orderNumber" width="150" >
        <template slot-scope="scope">
          <el-link @click="handleUpdate2(scope.row)" type="primary">{{scope.row.orderNumber}}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="客户" align="center" prop="customer" width="150" />
      <el-table-column label="始发地" align="center" prop="departure" width="160" />
      <el-table-column label="目的地" align="center" prop="destination" width="160" />
      <el-table-column label="提货状态" align="center" prop="pickupStatus"  width="150"/>
      <el-table-column label="发货地址" align="center" prop="shippingAddress"  width="180"/>
      <el-table-column label="收货地址" align="center" prop="receivingAddress" width="170"/>
      <el-table-column label="司机" align="center" prop="driver" width="150"/>
      <el-table-column label="车牌号" align="center" prop="licensePlate" width="150"/>
      <el-table-column label="手机号码" align="center" prop="phoneNumber" width="150"/>
      <el-table-column label="提货数量" align="center" prop="pickupQuantity" width="150"/>
      <el-table-column label="提货体积" align="center" prop="pickupVolume" width="150"/>
      <el-table-column label="提货重量" align="center" prop="pickupWeight" />
      <el-table-column label="提货运费合计" align="center" prop="pickupFreightTotal" />
      <el-table-column label="提货开始时间" align="center" prop="pickupStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pickupStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提货完成时间" align="center" prop="pickupCompleteTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pickupCompleteTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划发车时间" align="center" prop="plannedDepartureTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.plannedDepartureTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际发车时间" align="center" prop="actualDepartureTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualDepartureTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划到达时间" align="center" prop="plannedArrivalTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.plannedArrivalTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际到达时间" align="center" prop="actualArrivalTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualArrivalTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createdBy" />
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['pickup:pickup:edit']"-->
<!--          >修改</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['pickup:pickup:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['pickup:pickup:edit']"
          >详情</el-button>
<!--           <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="daozhan(scope.row)"-->
<!--            v-hasPermi="['pickup:pickup:edit']"-->
<!--          >整车到站</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="daozhan(scope.row)"-->
<!--            v-hasPermi="['pickup:pickup:edit']"-->
<!--          >订单到站</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改提货单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="提货单号" prop="pickupOrderNumber">
          <el-input v-model="form.pickupOrderNumber" placeholder="请输入提货单号" />
        </el-form-item>
        <el-form-item label="运单号" prop="waybillNumber">
          <el-input v-model="form.waybillNumber" placeholder="请输入运单号" />
        </el-form-item>
        <el-form-item label="订单号" prop="orderNumber">
          <el-input v-model="form.orderNumber" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="客户" prop="customer">
          <el-input v-model="form.customer" placeholder="请输入客户" />
        </el-form-item>
        <el-form-item label="发货地址" prop="shippingAddress">
          <el-input v-model="form.shippingAddress" placeholder="请输入发货地址" />
        </el-form-item>
        <el-form-item label="收货地址" prop="receivingAddress">
          <el-input v-model="form.receivingAddress" placeholder="请输入收货地址" />
        </el-form-item>
        <el-form-item label="司机" prop="driver">
          <el-input v-model="form.driver" placeholder="请输入司机" />
        </el-form-item>
        <el-form-item label="车牌号" prop="licensePlate">
          <el-input v-model="form.licensePlate" placeholder="请输入车牌号" />
        </el-form-item>
        <el-form-item label="手机号码" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="提货数量" prop="pickupQuantity">
          <el-input v-model="form.pickupQuantity" placeholder="请输入提货数量" />
        </el-form-item>
        <el-form-item label="提货体积" prop="pickupVolume">
          <el-input v-model="form.pickupVolume" placeholder="请输入提货体积" />
        </el-form-item>
        <el-form-item label="提货重量" prop="pickupWeight">
          <el-input v-model="form.pickupWeight" placeholder="请输入提货重量" />
        </el-form-item>
        <el-form-item label="提货运费合计" prop="pickupFreightTotal">
          <el-input v-model="form.pickupFreightTotal" placeholder="请输入提货运费合计" />
        </el-form-item>
        <el-form-item label="提货开始时间" prop="pickupStartTime">
          <el-date-picker clearable
            v-model="form.pickupStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择提货开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="提货完成时间" prop="pickupCompleteTime">
          <el-date-picker clearable
            v-model="form.pickupCompleteTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择提货完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="计划发车时间" prop="plannedDepartureTime">
          <el-date-picker clearable
            v-model="form.plannedDepartureTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择计划发车时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="实际发车时间" prop="actualDepartureTime">
          <el-date-picker clearable
            v-model="form.actualDepartureTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择实际发车时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="计划到达时间" prop="plannedArrivalTime">
          <el-date-picker clearable
            v-model="form.plannedArrivalTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择计划到达时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="实际到达时间" prop="actualArrivalTime">
          <el-date-picker clearable
            v-model="form.actualArrivalTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择实际到达时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable
            v-model="form.createdTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="操作确认"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <span>确定货物已到站吗？</span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="queding()">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import { listPickup, getPickup, delPickup, addPickup, updatePickup } from "@/api/pickup/pickup";

export default {
  name: "Pickup",
  components: {},
  props: [],
  data() {
    return {
      daterangePickupStartTime:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 提货单表格数据
      pickupList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        departure: null,
        destination: null,
        pickupStatus: null,
        pickupStartTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createdBy: [
          { required: true, message: "创建人不能为空", trigger: "blur" }
        ],
        createdTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ]
      }

    };

  },
  created() {
    this.getList();
  },
  methods: {
    dayin(){
      window.print();
    },
    /** 查询提货单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangePickupStartTime && '' != this.daterangePickupStartTime) {
        this.queryParams.params["beginPickupStartTime"] = this.daterangePickupStartTime[0];
        this.queryParams.params["endPickupStartTime"] = this.daterangePickupStartTime[1];
      }
      listPickup(this.queryParams).then(response => {
        this.pickupList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    daozhan(){
      this.dialogVisible = true;
    },
    queding(){
      this.dialogVisible = false;
      this.$message.success('操作成功');
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        pickupOrderNumber: null,
        waybillNumber: null,
        orderNumber: null,
        customer: null,
        departure: null,
        destination: null,
        pickupStatus: null,
        shippingAddress: null,
        receivingAddress: null,
        driver: null,
        licensePlate: null,
        phoneNumber: null,
        pickupQuantity: null,
        pickupVolume: null,
        pickupWeight: null,
        pickupFreightTotal: null,
        pickupStartTime: null,
        pickupCompleteTime: null,
        plannedDepartureTime: null,
        actualDepartureTime: null,
        plannedArrivalTime: null,
        actualArrivalTime: null,
        createdBy: null,
        createdTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    tostatus(pickupStatus){
      this.queryParams.pickupStatus = pickupStatus;
      this.getList();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加提货单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      // const id = row.id || this.ids
      // getPickup(id).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改提货单";
      // });
      const id = row.id || this.ids
      this.$router.push({path:'/pickup/pickupXq',query:{id:id}})
    },
    handleUpdate1(row) {
      const id = row.id || this.ids
      this.$router.push({path:'/operation/operationXq',query:{id:id}})
    },
    handleUpdate2(row) {
      const id = row.id || this.ids
      this.$router.push({path:'/operation/operationXq',query:{id:id}})
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePickup(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPickup(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除提货单编号为"' + ids + '"的数据项？').then(function() {
        return delPickup(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pickup/pickup/export', {
        ...this.queryParams
      }, `pickup_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
